function handles = displayVideoImages(handles);
% displayVideoImages
%
% Displays an array of video images in a figure
%
% Editing:
% gs june 2005
% gs may 2006 - modified for ephus etc
% ------------------------------------------------------

% identify the image files in the images directory
cd(handles.data.image.imgDir);
D = dir(handles.data.image.imgDir);

% weed out any directories 
D(find([D.isdir])) = []; 

% weed out any non-TIF files
toRemove = [];
for n = 1:numel(D)
    if ~strcmp(D(n).name(end-2:end), 'tif')
        toRemove = [toRemove n];
    end
end
D(toRemove) = [];

% set up the figure assuming less than 6 images to display
hfig(1) = figure('Color', 'w', 'DoubleBuffer', 'on', 'Units', 'normalized', ...
    'Position', [.2 .1 .42 .84]);

subRows = 3; 
subCols = 2;
plotnum = 0;

% In casee more than 6 files:
numFiles = numel(D);

if numFiles > subRows * subCols
    subRows = 4; 
    subCols = 2;
end
if numFiles > subRows * subCols
    subRows = 4; 
    subCols = 3;
end
if numFiles > subRows * subCols
    subRows = 5; 
    subCols = 3;
end
if numFiles > subRows * subCols
    rootNumFiles = ceil(sqrt(numFiles));
    subRows = rootNumFiles; 
    subCols = rootNumFiles;
end
    
for N = 1 : numel(D)
%     if ~D(N).isdir
        plotnum = plotnum + 1;
        hsub(plotnum) = subplot(subRows, subCols, plotnum);
        
        % read in the image file & convert to RGB format
        fullname = [handles.data.image.imgDir '\' D(N).name];
        I = imread(fullname);
%         R = ind2rgb(I, gray(256));
        R = I;
        
        % display image
        hSliceImg = imagesc(flipud(R));
        set(gca, 'YDir', 'normal');
        daspect([1 1 1]);
        
        % misc
        set(gca, 'XTickLabel', [], 'YTickLabel', []);
        title(D(N).name);
        
        % % distance scaling
        % try
        %     xrange = handles.data.acq.imageXrange;
        %     yrange = handles.data.acq.imageYrange;
        % catch
        %     xrange = 1900; % default param's from Ingrid's rig
        %     yrange = 1520;
        % end
        % set(hSliceImg, 'XData', [-xrange/2 xrange/2], 'YData', [-yrange/2 yrange/2]);
        % axis tight;
        
%     end
end

titleStr = [handles.data.analysis.experimentName ', images'];
text('String', titleStr, 'Units', 'Normalized', 'Position', [0 1.2420], ...
    'FontSize', 12, 'FontWeight', 'Bold', 'Parent', hsub(1), ...
    'Interpreter', 'none');

colormap(gray(256));